package ui;

import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;

/**
 * 미니맵 클래스
 */
public class MiniMap extends JPanel implements MouseListener, MouseMotionListener
{
	private BufferedImage buffer;
	private MainMap mainMap;

	public MiniMap(MainMap map)
	{
		super();
		mainMap = map;
		mainMap.setListener(this);

		setBounds(0, 0, 1024, 150);
		setBackground(Color.RED);

		addMouseListener(this);
		addMouseMotionListener(this);
	}

	@Override
	public void paint(Graphics g)
	{
		buffer = mainMap.getBuffer();
		g.drawImage(buffer, 0, 0, getWidth(), getHeight(), null);
	}

	@Override
	public void mouseClicked(MouseEvent e)
	{
	}

	@Override
	public void mousePressed(MouseEvent e)
	{
		mainMap.scrollTo(e.getX() * 5 - 512);
	}

	@Override
	public void mouseReleased(MouseEvent e)
	{
	}

	@Override
	public void mouseEntered(MouseEvent e)
	{
	}

	@Override
	public void mouseExited(MouseEvent e)
	{
	}

	@Override
	public void mouseDragged(MouseEvent e)
	{
		mainMap.scrollTo(e.getX() * 5 - 512);
	}

	@Override
	public void mouseMoved(MouseEvent e)
	{
	}
}